package com.mj.flink.examples.example.wordCount;

import com.mj.flink.examples.example.MyFlatMapFunction;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;

/**
 * 批处理
 */
public class WordCount {
    public static void main(String[] args) throws Exception {
        ExecutionEnvironment executionEnvironment= ExecutionEnvironment.getExecutionEnvironment();
        String resource = "D:\\mj\\workspace\\flink-examples\\flink-first-example\\src\\main\\resources\\WorkdCount.txt";
        DataSource<String> stringDataSource = executionEnvironment.readTextFile(resource);
        //实现flatMap函数接口
        DataSet<Tuple2<String,Integer>> resultSet = stringDataSource.flatMap(new MyFlatMapFunction()).groupBy(0).sum(1); //按照第1个word分组,按照第2个位置求和

        resultSet.print();
    }


}
